<?php

namespace App\Http\Controllers;
use App\Services\OrderPingppService;
use App\Services\TourOrderService;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;

/**
 *本文件用于测试，可以删除
 *
 * Class DemoTestController
 * @package App\Http\Controllers
 */
class DemoTestController extends BaseController{

    /**
     * 测试service方法
     */
    public function test(TourOrderService $tourOrderService){

        $result = $tourOrderService->getTuanQuantity(1);



        return $this->success($result);
    }

    public function testPayNotify(OrderPingppService $orderPingppService){
        $charge = [
            'order_no' => Input::get('order_no'),
            'transaction_no' => Input::get('transaction_no'),
            'amount' => Input::get('amount'),
        ];

        $result = $orderPingppService->updateOrderWhenSucceeded($charge);

        return $this->success($result);


    }

    public function testUploadImage(){

        $original = Input::file('original');
        $thumbnail = Input::file('thumbnail');

        $filepath = '/data/test/' . local_date_ymd(gmtime()) .'/' ;


        $original_filename = $filepath . 'original'.gmtime() . '.' . $original->getClientOriginalExtension();
        $fp = fopen($_FILES["original"]["tmp_name"],"rb");
        $buf = fread($fp,$_FILES["original"]["size"]);
        Storage::disk()->put($original_filename,$buf);
        unset($fp);
        unset($buf);
        unset($file);
        $original_url = complete_url($original_filename);

        $thumbnail_filename = $filepath . 'thumbnail'.gmtime() . '.' . $thumbnail->getClientOriginalExtension();
        $fp = fopen($_FILES["thumbnail"]["tmp_name"],"rb");
        $buf = fread($fp,$_FILES["thumbnail"]["size"]);
        Storage::disk()->put($thumbnail_filename,$buf);
        unset($fp);
        unset($buf);
        unset($file);

        $thumbnail_url = complete_url($thumbnail_filename);

        $data = [
            'original_url' => $original_url,
            'thumbnail_url' => $thumbnail_url
        ];
        return $this->success($data);
    }


    public function testAlipayRefund(){

    }

}